<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var res = [0]
        var rob = function (nums) {
            res.push(nums[0])
            if (nums.length == 0) return 0;
            if (nums.length == 1) return nums[0];
            return Math.max(nums[0]+rob(nums.slice(2)),nums[1]+rob(nums.slice(3)));
        };
        console.log(rob([2, 7, 9, 3, 1]))
    </script>
</body>

</html>